package fz.vrd.library.adapter;

import android.os.Parcelable;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @类功能说明:(带有滑动的fragmetn的适配器)
 */
public class FragmentPageAdapter extends FragmentStatePagerAdapter {

    List<Fragment> listFg = new ArrayList<Fragment>();

    String[] titles;

    public FragmentPageAdapter(FragmentManager fm, List<Fragment> listFg) {
        super(fm);
        this.listFg = listFg;
    }

    public FragmentPageAdapter(FragmentManager fm, List<Fragment> listFg, String[] titles) {
        super(fm);
        this.listFg = listFg;
        this.titles = titles;
    }

    public FragmentPageAdapter(FragmentActivity activity, List<Fragment> listFg) {
        this(activity.getSupportFragmentManager(), listFg);
    }

    public FragmentPageAdapter(FragmentActivity activity, List<Fragment> listFg, String[] titles) {
        this(activity, listFg);
        this.listFg = listFg;
        this.titles = titles;
    }

    public FragmentPageAdapter(Fragment fragment, List<Fragment> listFg) {
        this(fragment.getChildFragmentManager(), listFg);
    }

    public FragmentPageAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public int getCount() {

        return listFg == null ? 0 : listFg.size();
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        // TODO Auto-generated method stub
        super.destroyItem(container, position, object);
    }

    @Override
    public void finishUpdate(ViewGroup container) {
        // TODO Auto-generated method stub
        super.finishUpdate(container);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return (titles == null || titles.length < position) ? "" : titles[position];
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        // TODO Auto-generated method stub
        return super.instantiateItem(container, position);
    }

    @Override
    public void restoreState(Parcelable state, ClassLoader loader) {
        // TODO Auto-generated method stub
        super.restoreState(state, loader);
    }

    @Override
    public Parcelable saveState() {
        // TODO Auto-generated method stub
        return super.saveState();
    }

    @Override
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        // TODO Auto-generated method stub
        super.setPrimaryItem(container, position, object);
    }

    @Override
    public void startUpdate(ViewGroup container) {
        // TODO Auto-generated method stub
        super.startUpdate(container);
    }

    @Override
    public int getItemPosition(Object object) {
        return super.getItemPosition(object);
    }

    @Override
    public Fragment getItem(int arg0) {

        return listFg.get(arg0);
    }


}
